From b177d2ab56904191f0f2bd58ab837cd07e0f2bf8 Mon Sep 17 00:00:00 2001 From: Sondre Lefsaker Date: Sat, 2 May 2015 01:01:30 +0200 Subject: [PATCH] Pass the `arg_opts` from the command line further on to the CompileOptions. - The new tests verifies that the extra arguments gets appended to the command. One is for lib and one is for main - Currently the arguments gets passed on to *every* target that gets built, so the tests only contain one file each --- src/bin/rustc.rs | 2 +- src/cargo/ops/cargo_rustc/mod.rs | 4 +++ tests/test_cargo_rustc.rs | 58 ++++++++++++++++++++++++++++++-- 3 files changed, 60 insertions(+), 4 deletions(-) diff --git a/src/bin/rustc.rs b/src/bin/rustc.rs index f3d6fdf9d..72c8ad98d 100644 --- a/src/bin/rustc.rs +++ b/src/bin/rustc.rs @@ -85,7 +85,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { &options.flag_test, &options.flag_example, &options.flag_bench), - target_rustc_args: None, + target_rustc_args: options.arg_opts.as_ref().map(|a| &a[..]), }; ops::compile(&root, &opts).map(|_| None).map_err(|err| { diff --git a/src/cargo/ops/cargo_rustc/mod.rs b/src/cargo/ops/cargo_rustc/mod.rs index 4cb5f5b9b..d80b750a1 100644 --- a/src/cargo/ops/cargo_rustc/mod.rs +++ b/src/cargo/ops/cargo_rustc/mod.rs @@ -665,6 +665,10 @@ fn build_base_args(cx: &Context, cmd.arg("-g"); } + if let Some(ref args) = cx.build_config.target_rustc_args { + cmd.args(args); + } + if debug_assertions && opt_level > 0 { cmd.args(&["-C", "debug-assertions=on"]); } else if !debug_assertions && opt_level == 0 { diff --git a/tests/test_cargo_rustc.rs b/tests/test_cargo_rustc.rs index d119945a0..ccc90e18b 100644 --- a/tests/test_cargo_rustc.rs +++ b/tests/test_cargo_rustc.rs @@ -6,10 +6,14 @@ use hamcrest::{assert_that}; fn setup() { } -fn verbose_output_for_lib(p: &ProjectBuilder) -> String { +fn verbose_output_for_target(lib: bool, p: &ProjectBuilder) -> String { + let (target, kind) = match lib { + true => ("lib", "lib"), + false => ("main", "bin"), + }; format!("\ {compiling} {name} v{version} ({url}) -{running} `rustc src{sep}lib.rs --crate-name {name} --crate-type lib -g \ +{running} `rustc src{sep}{target}.rs --crate-name {name} --crate-type {kind} -g \ --out-dir {dir}{sep}target{sep}debug \ --emit=dep-info,link \ -L dependency={dir}{sep}target{sep}debug \ @@ -17,9 +21,14 @@ fn verbose_output_for_lib(p: &ProjectBuilder) -> String { ", running = RUNNING, compiling = COMPILING, sep = SEP, dir = p.root().display(), url = p.url(), + target = target, kind = kind, name = "foo", version = "0.0.1") } +fn verbose_output_for_target_with_args(lib: bool, p: &ProjectBuilder, args: &str) -> String { + verbose_output_for_target(lib, p).replace(" -g ", &format!(" -g {} ", args)) +} + test!(build_lib_for_foo { let p = project("foo") .file("Cargo.toml", r#" @@ -37,5 +46,48 @@ test!(build_lib_for_foo { assert_that(p.cargo_process("rustc").arg("--lib").arg("-v").arg("foo"), execs() .with_status(0) - .with_stdout(verbose_output_for_lib(&p))); + .with_stdout(verbose_output_for_target(true, &p))); +}); + +test!(build_lib_and_allow_unstable_options { + let p = project("foo") + .file("Cargo.toml", r#" + [package] + + name = "foo" + version = "0.0.1" + authors = ["wycats@example.com"] + "#) + .file("src/main.rs", r#" + fn main() {} + "#) + .file("src/lib.rs", r#" "#); + + assert_that(p.cargo_process("rustc").arg("--lib").arg("-v").arg("foo") + .arg("--").arg("-Z").arg("unstable-options"), + execs() + .with_status(0) + .with_stdout(verbose_output_for_target_with_args(true, &p, + "-Z unstable-options"))); +}); + +test!(build_main_and_allow_unstable_options { + let p = project("foo") + .file("Cargo.toml", r#" + [package] + + name = "foo" + version = "0.0.1" + authors = ["wycats@example.com"] + "#) + .file("src/main.rs", r#" + fn main() {} + "#); + + assert_that(p.cargo_process("rustc").arg("-v").arg("foo") + .arg("--").arg("-Z").arg("unstable-options"), + execs() + .with_status(0) + .with_stdout(verbose_output_for_target_with_args(false, &p, + "-Z unstable-options"))); }); -- 2.30.2